package de.g18.llmaa.gui.workspace.internalFrame.lizenzUebersicht;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import de.g18.llmaa.gui.IApp_Controler;
import de.g18.llmaa.gui.lizenzTree.TestTreeNode;
import de.g18.llmaa.gui.workspace.internalFrame.Abstract_InternalFrame;
import de.g18.llmaa.gui.workspace.internalFrame.lizenzUebersicht.treeTable.JTreeTable;
import de.g18.llmaa.gui.workspace.internalFrame.lizenzUebersicht.treeTable.LizenzTreeTableModel;
import de.g18.llmaa.logic.properties.PropertiesAndIconLoader;

public class InternalFrame_LizenzAnzeigen extends Abstract_InternalFrame {

	private JPanel panel_North;
	private JScrollPane scrollPane;
	private JButton button_Ausfahren;
	private boolean isOpen = false;

	JTreeTable treeTable;

	public InternalFrame_LizenzAnzeigen(IApp_Controler appCrtl) {

		setTitle("Lizenzübersicht");
		TestTreeNode node = new TestTreeNode(appCrtl);
		treeTable = new JTreeTable(new LizenzTreeTableModel(node));
		setFrameIcon(
				PropertiesAndIconLoader.getInstance().icon_LizenzUebersicht);
		initGUI();
		setSize(550, 500);
		setVisible(true);
	}

	private void initGUI() {

		setLayout(new BorderLayout());
		add(getPanel_North(), BorderLayout.NORTH);
		add(getScrollPane(), BorderLayout.CENTER);

	}

	public JPanel getPanel_North() {
		if (panel_North == null) {
			panel_North = new JPanel();
			panel_North.add(getButton_Ausfahren());
		}
		return panel_North;
	}

	public JButton getButton_Ausfahren() {
		if (button_Ausfahren == null) {
			button_Ausfahren = new JButton("Ausklappen");
			button_Ausfahren.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent arg0) {

					isOpen = !isOpen;
					treeTable.extractAll(isOpen);

					if (isClosed) {
						button_Ausfahren.setText("Einklappen");
					} else {
						button_Ausfahren.setText("Ausklappen");
					}

				}
			});
		}
		return button_Ausfahren;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane(
					JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
					JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
			scrollPane.setViewportView(treeTable);
		}
		return scrollPane;
	}

}
